/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Classes;

import amd.database.*;

/**
 *
 * @author Presario
 */
public class HasilExtract {
    Node terms[];
    TermDoc termDocs[][];
    Doc docs[];
    DbTermDocument dbTermDoc;
    ConnectDB conn;
    public void HasilExtract() {
        dbTermDoc = new DbTermDocument();
        conn=null;
        try {
            conn = new ConnectDB("jdbc:mysql://localhost:3306/db_amd_lsa", "root", "");
        } catch (Exception ex) {
           System.out.println(ex);
           System.exit(0);
        }
    }

    public void setTerms(Node[] t) {
        terms=t;
    }

    public void setTermDocs(TermDoc[][] t) {
        termDocs=t;
    }

    public void setDocs(Doc[] t) {
        docs=t;
    }

    public Node[] getTerms() {
        return terms;
    }
    public Node getTermKe(int i) {
        return terms[i];
    }

    public TermDoc[][] getTermDocs() {
        return termDocs;
    }

    public TermDoc getTermDocKe(int i, int j) {
        return termDocs[i][j];
    }

    public Doc[] getDocs() {
        return docs;
    }

    public Doc getDocKe(int i) {
        return docs[i];
    }

    public void HitungBobot() {
//        long wHitBobot=terms.length*docs.length;
//        long wHitSimilar=wHitBobot;
//        long intervHitBobot=(long)wHitBobot/20;
//        long intervHitSimilar=(long)wHitSimilar/20;
        int i = 0;
        double b;
        while(i<terms.length) {
            for(int j = 0; j<docs.length; j++) {
                if(termDocs[i][j].getFreq()!=0){
                    terms[i].setJdoc(terms[i].getJdoc()+1);
                }
            }
            i++;
        }
        i = 0; int j;
//        long jtermsxdocs=terms.length*docs.length;
        while(i<terms.length) {
            System.out.println("HitungBobot-"+i);
            for(j = 0; j<docs.length; j++) {
                System.out.println("Jumlah docs="+terms[i].getJdoc());
                b = (double)(termDocs[i][j].getFreq() * (Math.log10((float) (docs.length / terms[i].getJdoc()))+1));
                termDocs[i][j].setBobot(b);
//                if((i+1)*(j+1)==up*intervHitBobot){
//                    jTextFieldSaveDbBobot.setVisible(true);
//                    jTextFieldSaveDbBobot.setText(String.valueOf(up*20));
//                    up++;
//                }
//                jTextFieldSaveDbBobot.setVisible(true);
//                jTextFieldSaveDbBobot.setText(String.valueOf((i+1)*(j+1)*100/jtermsxdocs));
            }
            i++;
        }
    }

}
